<?php
/**
 * Created by PhpStorm.
 * User: coolinmind
 * Date: 20/02/2019
 * Time: 11:18
 */

namespace App\Modules\UCenter;


use App\Services\MyAddr\MyAddrIndex;

class Myaddr extends BaseUcenter
{
    /*用户收货地址列表*/
    public function myAddrList(): array
    {
        $res = $this->isLogin();
        if ($res['status'] !== SUCCESS_STATUS) {
            return need_login($res,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $res['res']['id'];
        return MyAddrIndex::MyAddr()->myAddrList($data);
    }
    /*管理员收货地址列表（可搜用户id）*/
    public function adminMyAddrList(): array
    {
        $res = $this->isLogin();
        if ($res['status'] !== SUCCESS_STATUS) {
            return need_login($res,'请登录');
        }
        $data = $this->postData;
        $data['is_del'] = 0;
        return MyAddrIndex::MyAddr()->adminMyAddrList($data);
    }
    /*用户添加收货地址*/
    public function addMyAddr(): array
    {
        $res = $this->isLogin();
        if ($res['status'] !== SUCCESS_STATUS) {
            return need_login($res,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $res['res']['id'];
        return MyAddrIndex::MyAddr()->addMyAddr($data);
    }
    /*用户删除收货地址*/
    public function delMyAddr(): array
    {
        $res = $this->isLogin();
        if ($res['status'] !== SUCCESS_STATUS) {
            return need_login($res,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $res['res']['id'];
        return MyAddrIndex::MyAddr()->delMyAddr($data);
    }
    /*用户修改收货地址*/
    public function altMyAddr(): array
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        $data['is_del'] = 0;
        return MyAddrIndex::MyAddr()->altMyAddr($data);
    }
    /*用户查看某条详情*/
    public function myAddrInfo(): array
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return MyAddrIndex::MyAddr()->myAddrInfo($data);
    }
    /*管理员删除收货地址*/
    public function adminDelMyAddr(): array
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        return MyAddrIndex::MyAddr()->adminDelMyAddr($data);
    }


}
